<?php

namespace Admin\Controller;
use User\Api\UserApi;

/**
 * 后台用户控制器
 */
class CommentController extends AdminController {
	
	public function _initialize(){


		
		parent::_initialize();
	}



   

//文章评论列表
public function index(){

    $get = $_GET;
    $this->assign('get',$get);
    $time = timeCondition($get['start_time'],$get['end_time']);
    if($time!=0){
        $where['bhy_comment.create_time'] = $time;
    }
    if($get['title']!=''){
        $where['bhy_comment.content|u.username'] = array('like','%'.$get['title'].'%');
    }
    $where['bhy_comment.status'] = array('gt',-1);
    $where['bhy_comment.pid'] = array('eq',0);
    $where['bhy_comment.content'] = array('neq','');

    //分页
    $listsCount = M('comment')->join('bhy_usermember as u on u.id=bhy_comment.uid')->where($where)->count();
    $Page       = new \Think\Page($listsCount,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    $show       = $Page->show();// 分页显示输出

    $list = M('comment')->join('bhy_usermember as u on u.id=bhy_comment.uid')->where($where)->order('bhy_comment.id desc')->field('bhy_comment.*,u.username,u.user_type,u.icon')->limit($Page->firstRow.','.$Page->listRows)->select();
    foreach ($list as $ke=>$ve){
        $list[$ke]['icon'] = picture($ve['icon']);
        $list[$ke]['title'] = modelField($ve['project_id'],'project','title');
        $list[$ke]['user_type'] = modelField($ve['user_type'],'userfz','title');
    }
    $this->assign('list',$list);
    $this->assign('_page',$show);
    $this->assign('listsCount',$listsCount);

    $this->display();
}

//文章评论审核
public function see(){
    $get = $_GET;
    $this->assign('get',$get);
    $where['bhy_comment.id'] = array('eq',$get['id']);
    $vo = M('comment')->join('bhy_usermember as u on u.id=bhy_comment.uid')->where($where)->field('bhy_comment.*,u.username,u.user_type,u.icon')->find();
    $vo['imgarr'] = explode(',',$vo['imgarr']);
    $vo['user_type'] = modelField($vo['user_type'],'userfz','title');
    $vo['title'] = modelField($vo['project_id'],'project','title');
    $this->assign('vo',$vo);
    //子集评论
    $whe['bhy_comment.pid'] = array('eq',$vo['id']);
    $whe['bhy_comment.status'] = array('eq',1);
    $son_list = M('comment')->join('bhy_usermember as u on u.id=bhy_comment.uid')->where($whe)->field('bhy_comment.*,u.username,u.user_type,u.icon')->select();
    foreach ($son_list as $ks=>$vs){
        $son_list[$ks]['icon'] = picture($vs['icon']);
        $son_list[$ks]['user_type'] = modelField($vs['user_type'],'userfz','title');
    }
    $this->assign('son_list',$son_list);



    $this->display();
}


  //删除
	public function del(){
		$id = I('request.id');
		
		if($id>0){
		  $lists = M('comment')->where('id='.$id)->delete();
		  if($lists){
			  $this->success('删除成功');
		  }
		}else{
				$this->error('参数错误');
		}
		$this->display();
	}

	//删除所有
    public function forverdel(){
	    $pt = $_REQUEST;
	    if($pt['method']=='deleteUser'){
            $where['id'] = array('in',implode(',',$pt['id']));

            $res = M('comment')->where($where)->delete();
            if($res){
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
            }
        }


    }





	
}
